725C - Hidden Word - CodeForces Solution


brute force constructive algorithms implementation strings *1600

Please click on ads to support us..

C++ Code:

#include<bits/stdc++.h>
#define int long long
#define N 200005
#define pb push_back
#define fi first
#define se second
#define pii pair<int,int>
using namespace std;
char s[N],ans[2][N]; int pi,pj,n=26;
signed main(){
	scanf("%s",s+1);
	for(int i=1;i<=n;i++) for(int j=i+1;j<=n+1;j++)
		if(s[i]==s[j]) pi=i,pj=j;
	if(pj-pi==1) return !printf("Impossible");
	int ln=(pj-pi+1)/2,p=pi,q,r0;
	for(int i=n/2-ln+1;i<=n/2;i++) ans[0][i]=s[p++];
	for(r0=n/2;p<pj;r0--) ans[1][r0]=s[p++];
	p=pi-1,q=n/2-ln; while(p&&q) ans[0][q--]=s[p--];
	if(p){
		for(int i=p;i;i--) ans[1][i]=s[p-i+1];
		p=pj+1; for(int i=r0;p<=n+1&&i;i--) ans[1][i]=s[p++];
	}else{
		p=pj+1; for(int i=r0;p<=n+1&&i;i--) ans[1][i]=s[p++];
		if(p<=n+1) for(int i=1;p<=n+1;i++) ans[0][i]=s[p++];
	}printf("%s\n%s",ans[0]+1,ans[1]+1);
	return 0;
}
				 		 				    			    		 				


Comments

Submit
0 Comments
More Questions

1630C - Paint the Middle
1630D - Flipping Range
1328A - Divisibility Problem
339A - Helpful Maths
4A - Watermelon
476A - Dreamoon and Stairs
1409A - Yet Another Two Integers Problem
977A - Wrong Subtraction
263A - Beautiful Matrix
180C - Letter
151A - Soft Drinking
1352A - Sum of Round Numbers
281A - Word Capitalization
1646A - Square Counting
266A - Stones on the Table
61A - Ultra-Fast Mathematician
148A - Insomnia cure
1650A - Deletions of Two Adjacent Letters
1512A - Spy Detected
282A - Bit++
69A - Young Physicist
1651A - Playoff
734A - Anton and Danik
1300B - Assigning to Classes
1647A - Madoka and Math Dad
710A - King Moves
1131A - Sea Battle
118A - String Task
236A - Boy or Girl
271A - Beautiful Year